create or replace function deletePosterminal(
	out xml, inout xml
	)
as
$$
	declare
		-- alias is name for stored procedure parameters
		executeStatusData 	alias for $1;
		posterminalData		alias for $2;
		
		vIdPosterminal 		bigint := null; -- posterminal id in database
		
		vIdNode				varchar(100) := '/posterminal/@id';
		
	begin
		vIdPosterminal := cast(extract_value(vIdNode, posterminalData) as bigint);
		-- first insert into trace table previous data
		insert into posterminalTrace(idPosTerminal, serialNumber, inventoryNumber, idModel, idCurrentPosLocation, idConnectionType)
			select idPosTerminal, serialNumber, inventoryNumber, idModel, idCurrentPosLocation, idConnectionType from posterminal
				where
					posterminal.idPosTerminal = vIdPosterminal
		;
		-- second delete row from original table
		delete from posterminal
			where
				idPosTerminal = vIdPosterminal;
		executeStatusData := statusCall(successcode(), 'Delete');
	end;
$$ language plpgsql VOLATILE;